package com.corpgovernment.travelstandard.impl;

import com.corpgovernment.api.travelstandard.service.IMbTravelstandIntlFlightTimeService;
import com.corpgovernment.api.travelstandard.vo.MbTravelstandFlightTimeVo;
import com.corpgovernment.api.travelstandard.vo.MbTravelstandIntlFlightTimeVo;
import com.corpgovernment.common.base.AbstractBaseService;
import com.corpgovernment.common.base.Page;
import com.corpgovernment.common.utils.ListUtils;
import com.corpgovernment.common.utils.ObjectUtils;
import com.corpgovernment.common.utils.PageUtils;
import com.corpgovernment.travelstandard.entity.db.MbTravelstandIntlFlightTime;
import com.corpgovernment.travelstandard.mapper.MbTravelstandIntelFlightTimeMapper;
import com.ctrip.corp.obt.shard.context.PageContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yuxing zhang
 * @date 2024/1/18 19:04
 */
@Service
public class MbTravelstandIntlFlightTimeService extends AbstractBaseService implements IMbTravelstandIntlFlightTimeService {

    @Autowired
    private MbTravelstandIntelFlightTimeMapper mbTravelstandIntelFlightTimeMapper;

    @Override
    public void insert(MbTravelstandIntlFlightTimeVo model) {
        mbTravelstandIntelFlightTimeMapper.insertSelective(ObjectUtils.copyProperties(model, MbTravelstandIntlFlightTime.class));
    }

    @Override
    public int update(MbTravelstandIntlFlightTimeVo model) {
        return mbTravelstandIntelFlightTimeMapper.updateByPrimaryKeySelective(ObjectUtils.copyProperties(model, MbTravelstandIntlFlightTime.class));
    }

    @Override
    public int delete(Long id) {
        return mbTravelstandIntelFlightTimeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Page page(MbTravelstandIntlFlightTimeVo model) {
        MbTravelstandIntlFlightTime param = ObjectUtils.copyProperties(model,MbTravelstandIntlFlightTime.class);
        PageContext.startPage(model.getPageNum(),model.getPageSize());
        List<MbTravelstandIntlFlightTime> list = mbTravelstandIntelFlightTimeMapper.list(param);
        return PageUtils.optPageBy(list, MbTravelstandIntlFlightTimeVo.class);
    }

    @Override
    public MbTravelstandIntlFlightTimeVo get(Long id) {
        return ObjectUtils.copyProperties(mbTravelstandIntelFlightTimeMapper.selectByPrimaryKey(id), MbTravelstandIntlFlightTimeVo.class);
    }

    @Override
    public List<MbTravelstandIntlFlightTimeVo> list(MbTravelstandIntlFlightTimeVo model) {
        return ListUtils.copyList(
                mbTravelstandIntelFlightTimeMapper.list(ObjectUtils.copyProperties(model, MbTravelstandIntlFlightTime.class)),
                MbTravelstandIntlFlightTimeVo.class
        );
    }

    @Override
    public int deleteByTsId(Long tsId) {
        return mbTravelstandIntelFlightTimeMapper.deleteByTsId(tsId);
    }
}
